package com.yu.crm.controller;


import com.yu.crm.domain.pojo.CrmBlacklistType;
import com.yu.crm.service.CrmBlacklistTypeService;
import com.yxzz.common.helper.valid.ValidatorHelpers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 黑名单分类表 前端控制器
 * </p>
 *
 * @author ct
 * @since 2020-07-01
 */

@Api(tags = "黑名单分类管理")
@RestController
@RequestMapping("/crm-blacklist-type")
public class CrmBlacklistTypeController {
    @Autowired
    CrmBlacklistTypeService crmBlacklistType;

    @ApiOperation(value = "新增或更新")
    @PostMapping(value = "/save-or-update")
    public void saveOrUpdate(@RequestBody @Valid CrmBlacklistType entity, BindingResult bindingResult) {
        ValidatorHelpers.notEmpty(entity.getBlacklistTypeName(), "姓名不能为空");
        ValidatorHelpers.validateParams(bindingResult);
        crmBlacklistType.saveOrUpdate(entity);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/remove-by-id/{id}")
    public void removeById(@PathVariable Long id) {
        //删除该表及该表下面的所有黑名单用户
        crmBlacklistType.removeBackListById(id);
    }


    @ApiOperation(value = "通过id查询")
    @GetMapping(value = "/get-by-id/{id}")
    public CrmBlacklistType getById(@PathVariable String id){


        return crmBlacklistType.getById(id);
    }

    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/list")
    public List<CrmBlacklistType> list() {
        return crmBlacklistType.list();
    }

}

